#include <stdio.h>
#include <string.h>
char month[12][5]={"Jan","Feb","Mar","Apr","May","June","July","Aug","Sept","Oct","Nov","Dec"};

int getMonth(char s[])
{
	int i=0;
	for(;i<12;i++){
		if(strcmp(s,month[i])==0){
			return i+1;
		}
	}
	return -1;
}
int runnian(int y)
{
	if(y%400||(y%4==0&&y%100!=0)) return 1;
	return 0;
}

int judge(int d,int m,int y)
{
	if(y>1000&&(m==1||m==3||m==5||m==7||m==8||m==10||m==12)&&(d>0&&d<=31)) return 1;
	if(y>1000&&(m==4||m==6||m==9||m==11)&&(d>0&&d<=30)) return 1;
	if(y>1000&&runnian(y)==1&&m==2&&(d>0&&d<=29)) return 1;
	if(y>1000&&runnian(y)==0&&m==2&&(d>0&&d<=28))  return 1;
	return 0;
}
int main()
{
	char src[40],yue[10];
	int d,m,y;
	while(gets(src)){
		//MM-DD-YYYY 
		if(src[2]=='-'&&src[5]=='-'){
			sscanf(src,"%d-%d-%d",&m,&d,&y);
			if(judge(d,m,y)==1)
				printf("%.2d-%.2d-%d\n",m,d,y); 
			else printf("Invalid\n");
		}
		//DD-MMM-YYYY 
		else if(src[2]=='-'&&src[6]=='-'){
			sscanf(src,"%d-%[^-]-%d",&d,yue,&y);
			m=getMonth(yue);
			printf("%d\n",m);
			if(judge(d,m,y)==1)
				printf("%.2d-%.2d-%d\n",m,d,y); 
			else printf("Invalid\n");
		}
		//MM/DD/YYYY
		else if(src[2]=='/'&&src[5]=='/'){
			sscanf(src,"%d/%d/%d",&m,&d,&y);
			if(judge(d,m,y)==1)
				printf("%.2d-%.2d-%d\n",m,d,y);
			else printf("Invalid\n");
		}
		//YYYY/MM/DD
		else if(src[4]=='/'&&src[7]=='/'){
			sscanf(src,"%d/%d/%d",&y,&d,&y);
			if(judge(d,m,y)==1)
				printf("%.2d-%.2d-%d\n",m,d,y);
			else printf("Invalid\n");
		}
		else{
			printf("Invalid\n");
		}
	}
}
